package com.ly.dingTalk.controller;

import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.ly.dingTalk.bean.user.DtUser;
import com.ly.dingTalk.bean.user.DtUserV2;
import com.ly.dingTalk.configuration.DtConfiguration;
import com.ly.dingTalk.dingcon.DtService;
import com.ly.dingTalk.error.DtErrorException;
import com.ly.dingTalk.service.DtUserService;

import lombok.extern.slf4j.Slf4j;

@RestController
@RequestMapping("/dt/info/{appKey}")
@Slf4j
public class DtInfoController {
	
	@GetMapping(path = {"/getUserInfo"})
	public DtUserV2 getUserInfo(String userId, @PathVariable("appKey") String appKey) throws DtErrorException {
		final DtService dtService = DtConfiguration.getDtService(appKey);
		DtUserService userService = dtService.getUserService();
		DtUser byId = userService.getById(userId);
		log.info("用户信息: {}", byId);
		DtUserV2 v2ById = userService.getV2ById(userId);
		log.info("用户信息v2: {}", v2ById.toJson());
		return v2ById;
	}
	
   @PostMapping(path = {"/createUserInfo"})
    public String createUserInfo(DtUserV2 user, @PathVariable("appKey") String appKey) throws DtErrorException {
        final DtService dtService = DtConfiguration.getDtService(appKey);
        DtUserService userService = dtService.getUserService();
        String createUserV2 = userService.createUserV2(user);
        log.info("用户信息: {}", createUserV2);

        return createUserV2;
    }

}
